package com.letoken.platform.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.pub.annotation.auth.Permission;
import com.letoken.platform.pub.annotation.pub.Trim;
import com.letoken.platform.pub.res.ApiResponse;
import com.letoken.platform.repo.admin.req.user.UserIdReq;
import com.letoken.platform.repo.app.dao.AppWithdrawConfigMapper;
import com.letoken.platform.repo.app.po.AppWithdrawConfig;
import com.letoken.platform.repo.app.req.user.IdReq;
import com.letoken.platform.repo.utlis.PageDataUtil;
import com.letoken.platform.repo.utlis.WebUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;


@Slf4j
@RestController
@RequestMapping("/app_withdraw_config")
public class AppWithdrawConfigController {

    @Resource
    private AppWithdrawConfigMapper appWithdrawConfigMapper;



    @Permission(uri = "/app_withdraw_config/add",qx = "/app_withdraw_config/add")
    @Trim
    @PostMapping("/add")
    public ApiResponse<?> add(@Validated @RequestBody IdReq req) {

        AppWithdrawConfig appWithdrawConfig = new AppWithdrawConfig();
        appWithdrawConfig.setUserId(req.getId());
        appWithdrawConfig.setCreateTime(LocalDateTime.now());
        appWithdrawConfigMapper.insert(appWithdrawConfig);
        return ApiResponse.create();
    }


    @Permission(uri = "/app_withdraw_config/page",qx = "/app_withdraw_config/page")
    @Trim
    @PostMapping("/page")
    public ApiResponse<?> page(@RequestBody UserIdReq req) {
        Page<AppWithdrawConfig> page = new Page<>(req.getPageReq().getPage(), req.getPageReq().getSize());
        appWithdrawConfigMapper.page(page, req.userId);
        return ApiResponse.create(PageDataUtil.getPageData(page));
    }


    @Permission(uri = "/app_withdraw_config/del",qx = "/app_withdraw_config/del")
    @Trim
    @PostMapping("/del")
    public ApiResponse<?> del(@Validated @RequestBody IdReq idReq) {
        log.error("del app_withdraw_config; op userId={}", WebUtils.getUserId());
        appWithdrawConfigMapper.deleteById(idReq.getId());
        return ApiResponse.create();
    }
}
